package com.block.account.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Getter
public enum ActionTypeEnum {

    CZ("CZ", "充值")
    ,TK("TK", "退款")

    ,XH("XH", "消耗")
    ,BD("BD", "补单")
    ,BK("BK", "补扣")

    ,CHANNEL_PAYOUT("CHANNEL_PAYOUT", "采量支出")
    ,COMPANY_PAYOUT("COMPANY_PAYOUT", "公司运营")
    ,STAFF_SALARY("STAFF_SALARY", "员工工资")
    ,STAFF_PERCENT("STAFF_PERCENT", "员工提成")
    ,AGENT_REBATE("AGENT_REBATE", "代理返点")

    ,TZ("TZ", "调账")

    ,INCOME("INCOME", "收入")
    ;

    static List<String> changAmountTypeList = new ArrayList<>();
    static List<String> updateMainTypeList = new ArrayList<>();
    static {
        /**
         * 需要转换成负数
         */
        changAmountTypeList.add(TK.getValue());
        changAmountTypeList.add(TZ.getValue());
        changAmountTypeList.add(XH.getValue());
        changAmountTypeList.add(BK.getValue());
        changAmountTypeList.add(BK.getValue());

        changAmountTypeList.add(CHANNEL_PAYOUT.getValue());
        changAmountTypeList.add(COMPANY_PAYOUT.getValue());
        changAmountTypeList.add(STAFF_SALARY.getValue());
        changAmountTypeList.add(STAFF_PERCENT.getValue());
        changAmountTypeList.add(AGENT_REBATE.getValue());

        updateMainTypeList.add(CZ.getValue());
        updateMainTypeList.add(TK.getValue());
    }

    private String value;
    private String name;

    ActionTypeEnum(String value, String name){
        this.value = value;
        this.name = name;
    }

    public static BigDecimal getChangeAmount(String actionType, BigDecimal changeAmount){
        if (changAmountTypeList.contains(actionType)){
            return BigDecimal.ZERO.subtract(changeAmount);
        }
        return changeAmount;
    }

    public static boolean updateMainAction(String actionType){
        if (updateMainTypeList.contains(actionType)){
            return true;
        }
        return false;
    }

    public static ActionTypeEnum getEntityByType(String actionType){
        for (ActionTypeEnum typeEnum : values()) {
            if (StrUtil.equals(typeEnum.getValue(), actionType)){
                return typeEnum;
            }
        }
        return null;
    }




}
